import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { asyncRouter, nomatch } from '@choerodon/boot';
import { PermissionRoute } from '@choerodon/master';

const index = asyncRouter(() => (import('./List')));

const Index = ({ match }) => {
  const getService = (type) => {
    if (type === 'organization') {
      return ['choerodon.code.organization.manager.task.ps.default'];
    }
    if (type === 'project') { // ctyun-项目层
      return ['choerodon.code.project.manager.task.ps.default'];
    }
    return 'choerodon.code.site.manager.task-detail.ps.default';
  };

  return (
    <Switch>
      <PermissionRoute
        exact
        path={match.url}
        component={index}
        service={(type) => getService(type)}
      />
      <Route path="*" component={nomatch} />
    </Switch>
  );
};

export default Index;
